import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)
import Login from '@/views/Login/Login.vue'
import layout from '@/views/Main.vue'

const router = new VueRouter({
  mode: 'history',
  routes: [
    { path: '/', name: '', redirect: '/login' },
    { path: '/login', name: 'login', component: Login },
    {
      path: '/',
      name: '布局',
      component: layout,
      children: [
        { path: 'home', name: '首页',component: () => import ( /* webpackChunkName: "home" */ "../views/components/home.vue") },
        { path: 'archive', name:'文档',component: () => import ( /* webpackChunkName: "archive" */ "../views/Archive/archive.vue")},
        { path: 'table', name:'基础表格',component: () => import ( /* webpackChunkName: "table" */ "../views/Table/list.vue")},
        { path: 'tabs', name:'tab选项卡',component: () => import ( /* webpackChunkName: "tab" */ "../views/Tabs/tab.vue")},
        { path: 'from', name:'基础表单',component: () => import ( /* webpackChunkName: "from" */ "../views/From/sheel.vue")},
        { path: 'upload', name:'文件上传',component: () => import ( /* webpackChunkName: "upload" */ "../views/Upload/upload.vue")},
      ]
      
    }
  ]
})

router.beforeEach((to, from, next) => {
    if (to.path === '/') {
      next();
    } else {
      let token = localStorage.getItem('TOKEN');
      if (token == null || token === '') {
        next();
      } else {
        next();
      }
    }
});

export default router
